Workflow Condition Template
The Workflow Condition template demonstrates how a BindAI workflow can make a runtime decision and continue execution through one of two configured paths. AConditionNode evaluates a predicate against the workflow context. Depending on whether the predicate returns True or False, the node adds the configured true or false node to the workflow execution queue.
This template introduces conditional branching into BindAI workflows.
Purpose
This template demonstrates how to:- Add a
ConditionNodeto a workflow - Evaluate runtime workflow context
- Define a true branch
- Define a false branch
- Route execution dynamically
- Use workflow variables when implementing predicates
Workflow Structure
A conditional workflow can be represented conceptually as:ConditionNode itself does not contain the branch node implementations.
Instead, it stores the identifiers of the nodes to execute when the predicate evaluates to True or False.
ConditionNode
The condition implementation is:Defining the Branches
The true and false branches are configured explicitly.Execution Flow
When the workflow executor reaches aConditionNode, it calls:
Decision Logic
The condition itself does not require a specific business rule. The predicate determines the decision. For example:Workflow Context
The predicate receives the workflow context:Example
Suppose a previous node determines whether a request should be approved.approved is True, the approval node is queued.
If approved is not True, the rejection node is queued.
Branch Configuration
A true branch is configured with:ConditionNode level.
If the predicate evaluates to True but no true node has been configured, no true-branch node is added to the execution queue.
Likewise, if the predicate evaluates to False but no false node has been configured, no false-branch node is added.
For predictable workflows, configure the branch paths that the workflow is expected to use.
Branching Example
A common approval workflow might look like:Agent Integration
An agent can produce information that a later condition evaluates. For example:- The agent performs AI-driven work.
- The workflow condition evaluates runtime state.
- The selected branch determines what executes next.
ConditionNode itself does not perform AI reasoning.
Conditions and Workflow Orchestration
Conditions are useful when a workflow needs deterministic orchestration around runtime data. For example:Common Use Cases
Conditional workflows can be useful for:- Approval decisions
- Validation results
- Eligibility checks
- Request routing
- Escalation decisions
- Status-based processing
- Threshold checks
- Classification results
- Business-rule evaluation
Predicate Design
A predicate should return a Boolean value:Condition vs Prompt Logic
Conditions are useful for deterministic workflow routing.
This does not mean prompts should never contain reasoning. Rather,
ConditionNode provides a clear mechanism for deterministic orchestration around runtime state.
Combining Conditions
Multiple conditions can be used in the same workflow. For example:Testing Both Branches
A condition should be tested with context values that exercise both outcomes. For example:Current Implementation Details
The currentConditionNode implementation:
Important Boundaries
No built-in Start Node
A condition workflow does not require a specialStartNode.
The workflow’s first added node becomes its starting node.
No built-in End Node
A condition workflow does not require a specialEndNode.
The workflow completes according to the normal workflow executor rules after the execution queue is exhausted or another terminal execution condition occurs.
The predicate receives the context
The condition does not receive a single variable value automatically. The predicate receives the completeWorkflowContext and decides what information to inspect.
Branches are node references
when_true() and when_false() store the identifiers of the selected nodes.
They do not execute those nodes immediately.
The workflow executor processes the queued node afterward.
Missing branches are possible
A true or false branch may be left unset. In that case, the corresponding branch does not add a node to the execution queue.Best Practices
- Keep predicates focused on the routing decision.
- Read runtime data from the workflow context.
- Use descriptive node identifiers.
- Configure both branches when both outcomes are meaningful.
- Test both true and false outcomes.
- Test missing or unexpected context values.
- Keep complex business logic outside the condition when possible.
- Use multiple conditions carefully so the workflow remains understandable.
- Prefer explicit workflow routing over hidden orchestration logic.
Related Templates
The condition pattern builds on the basic workflow model introduced in:08.1 workflow-basic.md
08.3 workflow-loop.md08.4 workflow-parallel.md08.5 workflow-human.md08.6 workflow-retry.md08.7 workflow-timeout.md08.8 workflow-schedule.md
Summary
The Workflow Condition template introduces deterministic branching into BindAI workflows. The essential pattern is:ConditionNode receives a predicate operating on the workflow context.
The predicate returns True or False, and the condition adds the corresponding configured node to the workflow execution queue.
This provides an explicit mechanism for routing workflow execution based on runtime state.